package com.zhuhan.controller;

import com.zhuhan.domain.Account;
import com.zhuhan.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller/*spring对Controller的注解，在xml文件中就不用写bean标签来配置*/
@RequestMapping("/account")
public class AccountController {

    @Autowired
    private AccountService accountService;

    /**
     * 查询所有数据
     *
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll(Model model) {
        System.out.println("controller中的findAll方法");
        List<Account> list = accountService.findAll();
        model.addAttribute("list", list);
        return "success";
    }

    /**
     * 添加数据
     * redirect：表示需要跳转到的方法
     *
     * @param account
     * @return
     */
    @RequestMapping("/addAccount")
    public String addAccount(Account account) {
        System.out.println("controller中的addAccount方法");
        accountService.addAccount(account);
        return "success";
    }
}